from ckeditor_uploader.fields import RichTextUploadingField

from users.models import User
from django.db import models


class Spit(models.Model):
    """吐槽列表"""
    user = models.ForeignKey(User, on_delete=models.CASCADE, verbose_name='用户')
    abstract = models.TextField(max_length=128,verbose_name='摘要')
    content = RichTextUploadingField(default='', verbose_name='吐槽详情')
    image = models.CharField(max_length=128,verbose_name='图片')
    create_time = models.DateTimeField(auto_now_add=True, verbose_name='吐槽时间')
    spit_like_count = models.IntegerField(default=0,verbose_name='吐槽点赞数')
    # is_like = models.BooleanField(default=False,verbose_name="是否点赞")
    # is_collect = models.BooleanField(default=False,verbose_name="是否收藏")
    comment_like_count = models.IntegerField(default=0,verbose_name='评论点赞数')
    share_count = models.IntegerField(default=0,verbose_name='分享数')
    is_delete = models.BooleanField(default=False)

    def __str__(self):
        return self.abstract

    class Meta:
        db_table = 'spit'
        verbose_name = '吐槽'
        verbose_name_plural = verbose_name


class Comments(models.Model):
    """评论"""
    spit = models.ForeignKey(Spit, on_delete=models.CASCADE, verbose_name='吐槽')
    user = models.ForeignKey(User, on_delete=models.CASCADE, verbose_name='用户')
    comment = models.CharField(max_length=256,verbose_name='评论内容')

    def __str__(self):
        return self.comment

    class Meta:
        db_table = 'comment'
        verbose_name = '评论'
        verbose_name_plural = verbose_name


class SpitCollection(models.Model):
    """吐槽收藏"""
    spit = models.ForeignKey(Spit,on_delete=models.CASCADE, verbose_name='吐槽')
    user = models.ForeignKey(User, on_delete=models.CASCADE, verbose_name='用户')
    collect_time = models.DateTimeField(verbose_name='收藏时间')

    class Meta:
        db_table = 'SpitCollection'
        verbose_name = '吐槽收藏'
        verbose_name_plural = verbose_name


class SpitLike(models.Model):
    """吐槽点赞"""
    spit = models.ForeignKey(Spit, on_delete=models.CASCADE, verbose_name='吐槽')
    user = models.ForeignKey(User, on_delete=models.CASCADE, verbose_name='用户')

    class Meta:
        db_table = 'SpitLike'
        verbose_name = '吐槽点赞'
        verbose_name_plural = verbose_name


class CommentLike(models.Model):
    """评论点赞"""
    spit = models.ForeignKey(Spit, on_delete=models.CASCADE, verbose_name='吐槽')
    user = models.ForeignKey(User, on_delete=models.CASCADE, verbose_name='用户')

    class Meta:
        db_table = 'CommentLike'
        verbose_name = '评论点赞'
        verbose_name_plural = verbose_name


class SpitShare(models.Model):
    """吐槽分享"""
    spit = models.ForeignKey(Spit, on_delete=models.CASCADE, verbose_name='吐槽')
    user = models.ForeignKey(User, on_delete=models.CASCADE, verbose_name='用户')

    class Meta:
        db_table = 'SpitShare'
        verbose_name = '吐槽分享'
        verbose_name_plural = verbose_name

